<template>
  <div class="md-nav-class-component">
    <div class="action-box" v-if="!isLogin">
      <a href="javascript:;" @click="toPage('/login')">登录</a> / <a href="javascript:;" @click="toPage('/register')">注册</a>
    </div>
    <div class="user-box" v-else>
      <!-- <a href="javascript:;" @click="toPage('/manage')">我的课程</a> -->
      <div class="user-center">
        <div class="avatar" @click="toPage('/manage')">
          {{userInfo.userType=='01'?userInfo.dept.deptName:userInfo.nickName}}<img src="@/assets/img/avatar.png" alt="">
        </div>
        <div class="user-center-panel">
          <!-- <div class="u-box" @click="toPage('/manage')">
            <div class="ava-box">
              <img :src="`/vide0-dev${userInfo.avatar}`" alt="">
            </div>
            <span>{{userInfo.userType=='01'?userInfo.dept.deptName:userInfo.nickName}}</span>
          </div>-->
          <ul class="u-list">
            <li class="u-item" @click="toPage('/manage')">
              <i class="el-icon-user"></i>我的课程
            </li>
            <li class="u-item" @click="handleLogout">
              <i class="el-icon-switch-button"></i>退出登录
            </li>
          </ul>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  data () {
    return {
      // isLogin: false
    }
  },
  computed: {
    isLogin () {
      return window.localStorage.getItem('isLogin')
    },
    userInfo () {
      return JSON.parse(window.localStorage.getItem('userInfo'))
    }
  },
  methods: {
    toPage (path) {
      this.$router.push(path)
    },
    handleLogout () {
      this.$store.state.isLogin = false
      this.$store.state.user = null
      localStorage.clear()
      window.location.href = '/login'
    }
  }
}
</script>
<style lang="less" scoped>
.md-nav-class-component {
  .action-box {
    margin-left: 20px;
    font-size: 16px;
    a {
      font-size: 16px;
      color:#fff;
      cursor: pointer;
      &:hover {
        color: #25c0a7;
      }
    }
  }
  .user-box {
    margin-left: 20px;
    font-size: 16px;
    display: flex;
    align-items: center;
    a {
      font-size: 16px;
      color: #545c63;
      cursor: pointer;
      &:hover {
        color: @md-primary-color;
      }
    }
    .user-center {
      margin-left: 10px;
      position: relative;
      padding: 20px 0;
      &:hover {
        .user-center-panel {
          display: block;
        }
        // .avatar {
        //   border: 2px solid @md-primary-color;
        // }
      }
      .avatar {
        display: inline-block;
        height: 32px;
        overflow: hidden;
        cursor: pointer;
        img {
          border: 2px solid #f3f5f6;
          width: 32px;
          height: 32px;
          border-radius: 50%;
          margin-left: 10px;
        }
      }
      .user-center-panel {
        position: absolute;
        right: 0px;
        top: 72px;
        z-index: 999;
        width: 300px;
        display: none;
        background: #fff;
        border-radius: 0 0 10px 10px;
        min-height: 60px;
        padding: 24px;
        box-sizing: border-box;
        .u-box {
          display: flex;
          align-items: center;
          .ava-box {
            width: 72px;
            height: 72px;
            border-radius: 50%;
            border: 2px solid #fff;
            margin-right: 12px;
            overflow: hidden;
            img {
              width: 100%;
              height: 100%;
            }
          }
          span {
            color: #07111b;
            font-size: 16px;
          }
        }
        .u-list {
          margin-top: 10px;
          display: flex;
          align-items: center;
          justify-content: space-between;
          .u-item {
            width: 49%;
            height: 40px;
            font-size: 14px;
            border-radius: 2px;
            background: #f8fafc;
            cursor: pointer;
            display: flex;
            align-items: center;
            padding-left: 20px;
            box-sizing: border-box;
            color: #1c1f21;
            i {
              margin-right: 6px;
              font-size: 16px;
              &:hover {
                color: #545c63;
              }
            }
            &:hover {
              background: #f3f5f6;
              color: #545c63;
            }
          }
        }
      }
    }
  }
}
</style>